// 检查 storage API 是否可用
const checkStorageAvailable = () => {
    return new Promise((resolve, reject) => {
      if (typeof chrome === 'undefined' || !chrome.storage || !chrome.storage.local) {
        reject(new Error('Storage API is not available'));
      } else {
        resolve();
      }
    });
  };
  
  // 关闭所有弹出窗口
const closeAllPopups = () => {
  const popups = document.querySelectorAll('.todo-input-container');
  popups.forEach(popup => popup.remove());
};
  
  // 添加一个简单的通知函数
function showNotification(message, isError = false) {
  const notification = document.createElement('div');
  notification.className = 'mark-anything-notification';
  
  // 将消息内容中的换行符转换为 HTML 的换行
  const formattedMessage = message.replace(/\n/g, '<br>');
  notification.innerHTML = formattedMessage;
  
  if (isError) {
    notification.classList.add('error');
  }
  
  // 如果是发送成功的消息，增加宽度和最大高度
  if (message.startsWith('发送成功：')) {
    notification.style.maxWidth = '400px';
    notification.style.maxHeight = '200px';
    notification.style.overflowY = 'auto';
    notification.style.whiteSpace = 'pre-wrap';
    notification.style.wordBreak = 'break-all';
  }
  
  document.body.appendChild(notification);
  
  // 3秒后自动消失
  setTimeout(() => {
    notification.classList.add('fade-out');
    setTimeout(() => {
      notification.remove();
    }, 300);
  }, 3000);
}
  
  // 导出到全局对象
window.markAnything = window.markAnything || {};
window.markAnything.utils = window.markAnything.utils || {};
window.markAnything.utils.checkStorageAvailable = checkStorageAvailable;
window.markAnything.utils.closeAllPopups = closeAllPopups;
window.markAnything.utils.showNotification = showNotification;